package biz.obake.team.touchprotector.features.upsidedown;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.c;
import biz.obake.team.touchprotector.g.d;
import java.util.Map;

public class b extends biz.obake.team.touchprotector.d.b implements SensorEventListener {

    /* renamed from: d  reason: collision with root package name */
    private d f1697d = new d(this, 9, 2, "UpsideDown");
    private boolean e = false;
    private Handler f = new Handler();

    class a implements Runnable {
        a() {
        }

        public void run() {
            b.this.j();
        }
    }

    /* renamed from: biz.obake.team.touchprotector.features.upsidedown.b$b  reason: collision with other inner class name */
    private class C0079b {

        /* renamed from: a  reason: collision with root package name */
        boolean f1699a;

        /* renamed from: b  reason: collision with root package name */
        boolean f1700b;

        /* renamed from: c  reason: collision with root package name */
        boolean f1701c;

        /* renamed from: d  reason: collision with root package name */
        boolean f1702d;
        boolean e;
        boolean f;
        int g;
        int h;

        private C0079b(b bVar) {
            this.f1699a = biz.obake.team.touchprotector.d.i.b.c();
            this.f1700b = !c.b("Sensors.Paused");
            this.f1701c = "Locked".equals(c.c("TPService.State"));
            this.f1702d = "Unlocked".equals(c.c("TPService.State"));
            this.e = biz.obake.team.touchprotector.g.a.g("lock_upside_down");
            this.f = biz.obake.team.touchprotector.g.a.g("unlock_right_side_up");
            this.g = biz.obake.team.touchprotector.g.a.j("upside_down_sensitivity");
            this.h = biz.obake.team.touchprotector.g.a.j("right_side_up_sensitivity");
        }

        /* synthetic */ C0079b(b bVar, a aVar) {
            this(bVar);
        }
    }

    public b() {
        if (g()) {
            this.f1697d = new d(this, 9, 2, "UpsideDown");
            this.e = false;
        } else if (e()) {
            this.f1697d = new d(this, 1, 2, "UpsideDown");
            this.e = true;
        }
    }

    public static void d(Map<String, String> map) {
        map.put("UpsideDown.State", "Neutral");
    }

    private static boolean e() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(1) != null;
    }

    public static boolean f() {
        return (g() || e()) && h();
    }

    private static boolean g() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(9) != null;
    }

    private static boolean h() {
        return biz.obake.team.android.a.a().getResources().getBoolean(R.bool.flags_phone);
    }

    private void i() {
        if (!this.f1697d.g()) {
            this.f1697d.h();
        }
    }

    /* access modifiers changed from: private */
    public void j() {
        C0079b bVar = new C0079b(this, (a) null);
        boolean z = true;
        boolean z2 = bVar.f1699a && bVar.f1700b && bVar.f1702d && bVar.e;
        if (!bVar.f1699a || !bVar.f1700b || !bVar.f1701c || !bVar.f) {
            z = false;
        }
        if (z2 || z) {
            i();
        } else {
            k();
        }
    }

    private void k() {
        if (this.f1697d.g()) {
            this.f1697d.j();
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void b(java.lang.String r6) {
        /*
            r5 = this;
            int r0 = r6.hashCode()
            r1 = 4
            r2 = 3
            r3 = 2
            r4 = 1
            switch(r0) {
                case -2104186565: goto L_0x0034;
                case -2066548004: goto L_0x002a;
                case 831789315: goto L_0x0020;
                case 1690883215: goto L_0x0016;
                case 2058828197: goto L_0x000c;
                default: goto L_0x000b;
            }
        L_0x000b:
            goto L_0x003e
        L_0x000c:
            java.lang.String r0 = "unlock_right_side_up"
            boolean r6 = r6.equals(r0)
            if (r6 == 0) goto L_0x003e
            r6 = 4
            goto L_0x003f
        L_0x0016:
            java.lang.String r0 = "Screen.State"
            boolean r6 = r6.equals(r0)
            if (r6 == 0) goto L_0x003e
            r6 = 0
            goto L_0x003f
        L_0x0020:
            java.lang.String r0 = "Sensors.Paused"
            boolean r6 = r6.equals(r0)
            if (r6 == 0) goto L_0x003e
            r6 = 1
            goto L_0x003f
        L_0x002a:
            java.lang.String r0 = "TPService.State"
            boolean r6 = r6.equals(r0)
            if (r6 == 0) goto L_0x003e
            r6 = 2
            goto L_0x003f
        L_0x0034:
            java.lang.String r0 = "lock_upside_down"
            boolean r6 = r6.equals(r0)
            if (r6 == 0) goto L_0x003e
            r6 = 3
            goto L_0x003f
        L_0x003e:
            r6 = -1
        L_0x003f:
            if (r6 == 0) goto L_0x004a
            if (r6 == r4) goto L_0x004a
            if (r6 == r3) goto L_0x004a
            if (r6 == r2) goto L_0x004a
            if (r6 == r1) goto L_0x004a
            goto L_0x005a
        L_0x004a:
            android.os.Handler r6 = r5.f
            r0 = 0
            r6.removeCallbacksAndMessages(r0)
            android.os.Handler r6 = r5.f
            biz.obake.team.touchprotector.features.upsidedown.b$a r0 = new biz.obake.team.touchprotector.features.upsidedown.b$a
            r0.<init>()
            r6.post(r0)
        L_0x005a:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.features.upsidedown.b.b(java.lang.String):void");
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
        String str = null;
        C0079b bVar = new C0079b(this, (a) null);
        float[] fArr = sensorEvent.values;
        float f2 = fArr[0];
        float f3 = fArr[1];
        float f4 = fArr[2];
        if (this.e) {
            double sqrt = Math.sqrt((double) (((f2 * f2) + (f3 * f3)) + (f4 * f4))) / 9.806650161743164d;
            if (sqrt < 0.9d || 1.1d < sqrt) {
                return;
            }
        }
        String c2 = c.c("UpsideDown.State");
        int degrees = (int) Math.toDegrees(Math.atan(((double) f3) / Math.sqrt((double) ((f2 * f2) + (f4 * f4)))));
        if (degrees < bVar.g && !c2.equals("UpsideDown")) {
            str = "UpsideDown";
        } else if (degrees > bVar.h && !"RightSideUp".equals(c2)) {
            str = "RightSideUp";
        }
        if (str != null) {
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("UpsideDown: " + str);
            c.g("UpsideDown.State", str);
        }
    }

    public void start() {
        if (f()) {
            super.start();
            j();
        }
    }

    public void stop() {
        if (f()) {
            super.stop();
            k();
        }
    }
}
